/**
 * Created by xxx on 2017/1/9.
 */
/**
 * 分页出事值
 * 分页数组
 * 没有数据时显示的内容
 * ajax出错的时候跳转的地址
 * 分页默认的条数
 * 创建一个闭包
 */
if(localStorage.pagecount == undefined){
    localStorage.pagecount = 15;
}
var pageList = [15,20,30,50,100],copyright="Copyright "+(new Date().getFullYear())+" 成都随寻教育科技有限公司";
var tableNoDataCount = "没有数据",invalidUrl = "../login/login.html",pagecount = localStorage.pagecount,pageListTop = -(pageList.length*20-8);
(function($, owner){
    owner.REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;
    owner.REGX_HTML_DECODE = /&\w+;|&#(\d+);/g;
    /**
     * ajax请求
     * url 地址
     * data 数据
     */
    owner.ajax = function(url,datas,type,callback,contentType=false){
        console.log(url+"?"+datas);
        $.ajax({
            url: url,
            type: type,
            dataType: "json",
            // async: false,//同步
            data: datas,
            timeout: 0,//请求时间
            contentType:contentType,//则数据再发送器会被转换成查询字符串通过false来回避
            processData: false,//禁发送数据格式自动转换
            success: function(data){
                console.log(data);
                callback(data);
            }.bind(this),
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                var error_text = XMLHttpRequest.responseText;
                if(error_text.indexOf("没有权限") > -1){
                    window.location.href = "../errorpage/404.html";
                    return;
                }else if(error_text.indexOf("系统") > -1){
                    window.location.href = "../errorpage/500.html";
                    return;
                }
                // top.location.href = invalidUrl;
            }
        });
    };
    owner.imagesUrl = config_sx.showImagesUrl+'/images/';//'http://192.168.2.12/images/';//测试环境
    // owner.imagesUrl = 'http://i.17find.com/images/';//线上
    /**
     * 上传图片
     */
    owner.uploadImg = function (element,datas,callback) {
        var pic = $(element)[0].files[0];
        var data = new FormData();
        data.append('file', pic);
        $.ajax({
            // url:serverUrl+"/upload/uploadPic",
            // url:"http://api.17find.com/upload/uploadPic?token=eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzMzc4MSIsImlhdCI6MTUwNjE0ODI0NSwiaXNzIjoiMTUyMDgyMDY4MDgiLCJhdWQiOiJndWFyZGlhbiJ9.YpztKWHAVdEXwzdELZLSsvF5M4tuR-rTMa5oYYVOmjA",
            url:config_sx.uploadImgUrl+"/upload/uploadPic?token=eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzMzc4MSIsImlhdCI6MTUwNjE0ODI0NSwiaXNzIjoiMTUyMDgyMDY4MDgiLCJhdWQiOiJndWFyZGlhbiJ9.YpztKWHAVdEXwzdELZLSsvF5M4tuR-rTMa5oYYVOmjA",
            type:"post",
            // Form数据
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success:function(data){
                callback(data);
            }
        });
    };
    /**
     * ajax请求
     * url 地址
     * data 数据
     */
    owner.ajax_sendMsg = function(url,datas,callback){
        // console.log(datas);
        $.ajax({
            url: url,
            //type: "post",
            dataType: "json",
            // async: false,//同步
            data: "param="+datas,
            timeout: 0,//请求时间
            contentType:"application/json",//则数据再发送器会被转换成查询字符串通过false来回避
            //processData: false,//禁发送数据格式自动转换
            success: function(data){
                console.log(data);
                callback(data);
            }.bind(this),
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                suixun.hideLoding();//隐藏加载中
                var hrefUrl = location.href;
                if(hrefUrl.indexOf("user/listRole") > -1 || hrefUrl.indexOf("user/queryUser") > -1 ){//|| url.indexOf("user/") > -1
                    //top.location.href = "../"+invalidUrl;
                }else{
                    //top.location.href = invalidUrl;
                }
            }
        });
    };
    /**
     * 替换所有的回车换行
     * @param content
     * @return {*}
     * @constructor
     */
    owner.TransferString = function(content,repl="") {
        var string = content;
        try{
            string=string.replace(/\r\n/g,repl);
            string=string.replace(/\n/g,repl);
        }catch(e) {
            alert(e.message);
        }
        return string;
    };
    /**
     * 数组去重
     * @param arr
     */
    owner.isRepeatArray = function (arr) {
        let hash = {};
        for(let j in arr) {
            if(hash[arr[j]])
                return true;
            hash[arr[j]] = true;
        }
        return false;
    };
    /**
     *
     * suixun.formatTime('yyyy-MM-dd h:m:s')
     * @param format
     * @returns {*}
     */
    owner.formatTime = function(format) {
        var date = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S+": this.getMilliseconds()
        };
        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1
                    ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
        }
        return format;
        };
    /**
     * 确认消息框-有标题
     * 例子： suixun.confirm("用户名不能包含特殊字符!","消息提示",function(rel){alert(e);});
     * 这个函数写得很差，可以优化
     */
    owner.confirm = function(content,title,callback){
        if($(".popupFrame").siblings().length > 0){
            return;
        }
        var html = '<div class="model_layout"></div><div class="infoMain"><div class="popup_tit"><span class="popup_title">'+(title == undefined?"消息提示":title)+'<span></div>' +
            '<div class="popup_con"><span class="popup_content">'+content+'<span></div><div class="popup_bun">' +
            '<a id="popup_no" href="javascript:void(0);" >取消</a><a type="button" id="popup_yes" href="javascript:void(0);" >确定</a></div></div>';
        //'<input type="button" id="popup_no" class="haveTit" value="取消"><input type="button" class="haveTit" id="popup_yes" value="确定"></div></div>';
        owner.createParentDiv();//没有就创建依赖div
        $(".popupFrame").html(html);
        /**
         * 点击取消
         */
        $("#popup_no").click(function(){
            if(undefined != callback){
                callback(false);//回调
            }
            $(".popupFrame").remove();
        });
        /**
         * 点击确认
         */
        $("#popup_yes").click(function(){
            if(undefined != callback) {
                callback(true);//回调
            }
            $(".popupFrame").remove();
        });
        //键盘事件
        document.onkeypress = function(e){
            var ev = document.all ? window.event : e;
            var eleObj = document.getElementById("popup_yes");
            if(ev.keyCode==13 && eleObj) {
                if(undefined != callback){
                    callback(true);//回调
                }
                $(".popupFrame").remove();
            }
        }
    };
    /**
     * 确认消息框-没有标题
     * 例子： suixun.confirm("用户名不能包含特殊字符!","消息提示",function(rel){alert(e);});
     * 这个函数写得很差，可以优化
     */
    owner.confirm_noTit = function(content,callback){
        if($(".popupFrame").siblings().length > 0){
            return;
        }
        var html = '<div class="model_layout"></div><div class="infoMain">' +
            '<div class="popup_con noTitle"><span class="popup_content">'+content+'<span></div><div class="popup_bun" >' +
            '<a id="popup_no" href="javascript:void(0);" >取消</a><a type="button" id="popup_yes" href="javascript:void(0);" >确定</a></div></div>';
        owner.createParentDiv();//没有就创建依赖div
        $(".popupFrame").html(html);
        /**
         * 点击取消
         */
        $("#popup_no").click(function(){
            if(undefined != callback){
                callback(false);//回调
            }
            $(".popupFrame").remove();
        });
        /**
         * 点击确认
         */
        $("#popup_yes").click(function(){
            if(undefined != callback){
                callback(true);//回调
            }
            $(".popupFrame").remove();
        });
        //键盘事件
        document.onkeypress = function(e){
            var ev = document.all ? window.event : e;
            var eleObj = document.getElementById("popup_yes");
            if(ev.keyCode==13 && eleObj) {
                if(undefined != callback){
                    callback(true);//回调
                }
                $(".popupFrame").remove();
            }
        }
    };
    /**
     * 警告消息框
     */
    owner.alert = function(content,title,callback){
        if($(".popupFrame").siblings().length > 0){
            return;
        }
        var html = '<div class="model_layout"></div><div class="infoMain"><div class="popup_tit"><span class="popup_title">'+(title == undefined?"消息提示":title)+'<span></div>' +
            '<div class="popup_con"><span class="popup_content">'+content+'<span></div>' +
            '<div class="popup_bun"><span id="popup_ok" >确定</span></div></div>';
        owner.createParentDiv();//没有就创建依赖div
        $(".popupFrame").html(html);

        /**
         * 关闭弹出框
         */
        $(".popup_bun").click(function(){
            if(callback != undefined){
                callback(true);//回调
            }
            $(".popupFrame").remove();
        });
        //键盘事件
        document.onkeypress = function(e){
            var ev = document.all ? window.event : e;
            var eleObj = document.getElementById("popup_ok");
            if(ev.keyCode==13 && eleObj) {
                if(undefined != callback){
                    callback(true);//回调
                }
                $(".popupFrame").remove();
            }
        }
    };
    /**
     * 警告消息框
     */
    owner.alert = function(content,callback){
        if($(".popupFrame").siblings().length > 0){
            return;
        }
        var html = '<div class="model_layout"></div><div class="infoMain"><div class="popup_tit"><span class="popup_title">消息提示<span></div>' +
            '<div class="popup_con"><span class="popup_content">'+content+'<span></div>' +
            '<div class="popup_bun"><span id="popup_ok" >确定</span></div></div>';
        owner.createParentDiv();//没有就创建依赖div
        $(".popupFrame").html(html);
        /**
         * 关闭弹出框
         */
        $(".popup_bun").click(function(){
            if(callback != undefined){
                callback(true);//回调
            }
            $(".popupFrame").remove();
        });
        //键盘事件
        document.onkeypress = function(e){
            var ev = document.all ? window.event : e;
            var eleObj = document.getElementById("popup_ok");
            if(ev.keyCode==13 && eleObj) {
                if(undefined != callback){
                    callback(true);//回调
                }
                $(".popupFrame").remove();
            }
        }
    };
    /**
     * 提示消息框
     * 移动端使用
     * 3s后淡出
     */
    owner.tips = function(content,callback){
        if($(".tipFrame").siblings().length > 0){
            return;
        }
        var html = '<div class="model_layout"></div><div class="infoMain"><span>'+content+'</span></div>';
        owner.createParentTipDiv();//没有就创建依赖div
        $(".tipFrame").html(html);
        /**
         * 关闭提示消息框
         */
        setTimeout(function () {
            if(callback != undefined){
                callback(true);//回调
            }
            $(".tipFrame").fadeOut(500);
            setTimeout(function () {
                $(".tipFrame").remove();
            },500);
        },2000);
    };
    /**
     * 创建依赖div
     * 弹出框的时候调用
     */
    owner.createParentDiv = function () {
        $(document.body).append("<div id='popupFrame' class='popupFrame'></div>");
    };
    /**
     * 创建依赖div
     * 移动端使用
     * 提示框的时候调用
     */
    owner.createParentTipDiv = function () {
        $(document.body).append("<div id='tipFrame' class='tipFrame'></div>");
    };
    /**
     * 获取url后面跟的值
     * 比如:http://192.168.1.4/mall/wap/Famous_sale/famous_series.html?series=12
     * 传入 series 获得的值为“12”
     */
    owner.urlpara = function (key){
        var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
        var result = window.location.search.substr(1).match(reg);
        return result?decodeURIComponent(result[2]):"";
    };
    /**
     * 获取当前时间
     * 获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”
     */
    owner.getFormatDate = function(){
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var hours = date.getHours(),
            min = date.getMinutes(),
            sec = date.getSeconds();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        if(hours < 10){
            hours = "0"+hours;
        }
        if(min < 10){
            min = "0"+min;
        }
        if(sec < 10){
            sec = "0"+sec;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + hours + seperator2 + min
            + seperator2 + sec;
        return currentdate;
    };
    /**
     * json 排序 可以按数字 和字符串
     * data 为json数据 filed 为字段
     * rev 为排序方式false为小到大，true反之
     * primer:String parseInt
     * 调用方式：json.sort(suixun.jsonSort(filed, rev, primer));
     * 例子：data.sort(suixun.jsonSort('time', true, String))：把时间按照由大到小的排序方式排序
     */
    owner.jsonSort = function(filed, rev, primer){
        rev = (rev) ? -1 : 1;
        return function (a, b) {
            a = a[filed];
            b = b[filed];
            if (typeof (primer) != 'undefined') {
                a = primer(a);
                b = primer(b);
            }
            if (a < b) { return rev * -1; }
            if (a > b) { return rev * 1; }
            return 1;
        }
    };
    /**
     * 验证是否为json格式
     * 是返回true 反之 好像不行
     */
    owner.isJson = function(obj){
        var isjson = typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length;
        return isjson;
    };
    /**
     * 隐藏加载中模糊层
     * 淡出效果500ms
     * time:正整数
     */
    owner.hideLoding = function (time) {
        if(time == undefined){
            $(".pageLoding").fadeOut(time);
        }else{
            $(".pageLoding").fadeOut(500);
        }
    };
    /**
     *显示加载中模糊层
     */
    owner.showLoding = function () {
        $(".pageLoding").show();
    };
    /**
     * 判断是移动端还是PC端
     */
    owner.isPC = function () {
        var sUserAgent = navigator.userAgent.toLowerCase();
        var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
        var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
        var bIsMidp = sUserAgent.match(/midp/i) == "midp";
        var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
        var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
        var bIsAndroid = sUserAgent.match(/android/i) == "android";
        var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
        var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
        if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
            return false;
        } else {
            return true;
        }
    };
    /**
     * 获取上传文件大小
     * @param element
     * @returns {*}
     */
    owner.fileSize = function(element){
        try {
            var fileSize = 0;
            // for IE
            if (window.ActiveXObject) {
                // before making an object of ActiveXObject,
                // please make sure ActiveX is enabled in your IE browser
                var objFSO = new ActiveXObject("Scripting.FileSystemObject");
                var filePath = element.get(0).value;
                var objFile = objFSO.getFile(filePath);
                fileSize = objFile.size; //size in kb
            }
            // for FF, Safari, Opeara and Others
            else {
                fileSize = element.get(0).files[0].size; //size in kb
            }

            //fileSize = fileSize / 1048576; //size in mb

            return fileSize;
        }
        catch (e) {
            return null;
        }
    };
    /**
     * 富文本编辑器
     */
    owner.editor = function (editorEle='editor') {
        /**
         * 基于UEditor开发的H5图文页面编辑器
         * Create by YaoQiao on 2017-01-11
         */
        var htmlObject = {};
        (function(){
            init();
        })();
        function init(){
            createEditor();
            addEvent();
        }
        /**
         * 添加事件侦听
         */
        function addEvent(){
            //添加预览功能
            addPreviewFun();
            //添加发布功能
            addSubmitFun();
        }

        /**
         * 创建编辑器
         */
        function createEditor(){
            //初始化编辑
            var ue = UE.getEditor(editorEle,{
                initialFrameWidth:1000,
                initialFrameHeight:400,
                initialStyle:'p{font-family:微软雅黑;font-size:16px;}',
                toolbars: [['fullscreen','source', '|', 'undo', 'redo','|','bold','italic','underline','fontborder','strikethrough','spechars','link','superscript', 'subscript','removeformat','formatmatch','|','forecolor','backcolor','insertorderedlist','insertunorderedlist','|','rowspacingtop','rowspacingbottom','lineheight','|','paragraph','fontfamily','fontsize','|','indent','justifyleft','justifycenter','justifyright','justifyjustify','|','imagenone','imageleft','imageright','imagecenter','|','insertimage','insertvideo','|','horizontal','inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols']],
                maximumWords:9999999,
                scaleEnabled:false,
                elementPathEnabled:false,
                wordCount:false,
                // autoHeightEnabled:false,
                autoHeightEnabled:true,//是否自动长高,默认true
                imagePopup:true,
                insertorderedlist:{
                    'decimal' : '' ,//'1,2,3...'
                    'lower-alpha' : '' ,// 'a,b,c...'
                    'lower-roman' : '' ,//'i,ii,iii...'
                    'upper-alpha' : '' ,//'A,B,C'
                    'upper-roman' : ''//'I,II,III...'
                },
                insertunorderedlist : {
                   'circle' : '',  // '○ 小圆圈'
                   'disc' : '',    // '● 小圆点'
                   'square' : ''   //'■ 小方块'
                }
            });
            htmlObject.editor = ue;
        }
        /**
         * 将当前页面中的数据添加至htmlObject对象中
         */
        function combineContent(){
            if(!htmlObject) return;
            //添加标题
            var title = $("#bannerTitle").val();
            htmlObject.articleTitle = title;
            //添加作者
            htmlObject.articleAuthor = localStorage.userName;
            //添加文章
            var article = htmlObject.editor.getContent();
            htmlObject.articleContent = article;
            //添加封面
            var articleCoverImg = [];
            if(htmlObject.singleModel){
                var file_preview = $("#file_preivew0");
                var _data = file_preview.attr("src");
                if(_data){
                    articleCoverImg.push();
                }
            }else{
                var file_previews = $(".three-images .single-preivew");
                for(var i=0 ;i < file_previews.length;i++){
                    var _data = $(file_previews[i].attr("src"));
                    if(_data){
                        articleCoverImg.push(data);
                    }
                }
            }
            htmlObject.articleCoverImg = articleCoverImg;
        }

        /**
         * 检查内容是否完善，并作出对应的提示
         *  -检查是否有标题
         * 	-检查是否输入作者
         *  -检查是否有封面
         *  @return {Boolean} 如果内容完善，返回true
         */
        function checkContent(){
            //检查是否有标题
            if(htmlObject.articleTitle == null || htmlObject.articleTitle==""){
                suixun.alert("请检查是否输入文章标题！");
                return false;
            }
            //检查是否有封面
            if(htmlObject.articleCoverImg == null || htmlObject.articleCoverImg.length < 1){
                suixun.alert("请检查是否上传封面！");
                return false;
            }
            return true;
        }

        /**
         * 添加发布功能
         */
        function addSubmitFun(){
            var sub_btn = $("#button-save");
            sub_btn.on("click",function(){
                //组合数据
                combineContent();
                //检查数据
                if(checkContent()){
                    //TODO how to submit the content to server.
                    console.log("the submit function not open.");
                }
            });
        }
        /**
         * 添加预览功能
         */
        function addPreviewFun(){
            var pre_btn = $(".button-preview");
            var pre_layer = $(".preview-layer");
            // var pre_bg = $(".preview-bg");
            var pre_bg = $(".preview-bg, .close");
            pre_btn.on("click",function(){
                updatePreviewHtml();
                pre_layer.show();
                resetPrePhoneCss();
            });
            pre_bg.on("click",function(){
                pre_layer.hide();
            });

            //预览图片居中样式
            var css_str = {};
            var pre_phone = $(".preview-phone");
            var pos_left = 0;
            var pos_top = 0;
            $(window).resize(function () {
                pos_left = $(window).width() / 2 - pre_phone.width() / 2;
                pos_top = $(window).height() / 2 - pre_phone.height() / 2;
                css_str = {
                    left:pos_left + "px",
                    top:pos_top + "px"
                };
                pre_phone.css(css_str);
            });
            //重置预览手机页面的CSS
            function resetPrePhoneCss(){
                pos_left = $(window).width() / 2 - pre_phone.width() / 2;
                pos_top = $(window).height() / 2 - pre_phone.height() / 2;
                css_str = {
                    left:pos_left + "px",
                    top:pos_top + "px"
                }
                pre_phone.css(css_str);
            }
            //初始化时设置预览手机元素位置
            resetPrePhoneCss();
        }

        /**
         * 更新预览页面显示内容
         */
        function updatePreviewHtml(){
            var ifr_document = document.getElementById("preview-html").contentWindow.document;
            if(ifr_document){
                //设置标题
                var title_str = $("#bannerTitle").val();
                var ifr_title = $(ifr_document).find(".article-title .title");
                ifr_title.html(title_str);
                //设置作者
                var ifr_author = $(ifr_document).find(".article-top .article-time");
                ifr_author.html("文："+localStorage.userName);

            }
            //设置正文
            if(ifr_document && htmlObject.editor){
                var content_str = htmlObject.editor.getContent();
                var ifr_content = $(ifr_document).find(".article-content");
                //表格宽度超过屏幕出现滚动条
                content_str = content_str.replace(/<table/g,'<div style="overflow: auto;  width: 100%;"><table');
                content_str = content_str.replace(/<\/table>/g,'<\/table><\/div>');
                ifr_content.html(content_str);
            }
        }
        return htmlObject.editor;
    };
    // /**
    //  * 资讯文章预览
    //  */
    // owner.articlePreview = function () {
    //     var pre_layer = $(".preview-layer");
    //     updatePreviewHtml();
    //     pre_layer.show();
    //     resetPrePhoneCss();
    //     /**
    //      * 更新预览页面显示内容
    //      */
    //     function updatePreviewHtml(UE){
    //         var ifr_document = document.getElementById("preview-html").contentWindow.document;
    //         if(ifr_document){
    //             //设置标题
    //             var title_str = $("#bannerTitle").val();
    //             var ifr_title = $(ifr_document).find(".article-title .title");
    //             ifr_title.html(title_str);
    //             //设置作者
    //             var ifr_author = $(ifr_document).find(".article-top .article-time");
    //             ifr_author.html("文："+localStorage.userName);
    //
    //         }
    //         //设置正文
    //         if(ifr_document && UE){
    //             var content_str = UE.getContent();
    //             var ifr_content = $(ifr_document).find(".article-content");
    //             //表格宽度超过屏幕出现滚动条
    //             content_str = content_str.replace(/<table/g,'<div style="overflow:auto;width:100%;"><table');
    //             content_str = content_str.replace(/<\/table>/g,'<\/table><\/div>');
    //             ifr_content.html(content_str);
    //         }
    //     }
    //     //预览图片居中样式
    //     var css_str = {};
    //     var pre_phone = $(".preview-phone");
    //     var pos_left = 0;
    //     var pos_top = 0;
    //     $(window).resize(function () {
    //         pos_left = $(window).width() / 2 - pre_phone.width() / 2;
    //         pos_top = $(window).height() / 2 - pre_phone.height() / 2;
    //         css_str = {
    //             left:pos_left + "px",
    //             top:pos_top + "px"
    //         };
    //         pre_phone.css(css_str);
    //     });
    //     //重置预览手机页面的CSS
    //     function resetPrePhoneCss(){
    //         pos_left = $(window).width() / 2 - pre_phone.width() / 2;
    //         pos_top = $(window).height() / 2 - pre_phone.height() / 2;
    //         css_str = {
    //             left:pos_left + "px",
    //             top:pos_top + "px"
    //         };
    //         pre_phone.css(css_str);
    //     }
    // };
    /**
     * 获取分页信息
     * @param index 开始的条数位置
     * @param pagecount 每页条数
     * @param totle 总条数
     * @return pageInfo 分页信息
     */
    owner.getPageInfo = function (index,pagecount,totle) {
        var pageInfo = {
            currentpage:1,//当前页
            pageLeft: 0,//0是不可点击，1反之
            pageRight: 0,//0是不可点击，1反之
            totlepage: 1,//总页数
        };
        pageInfo.totlepage = Math.ceil(totle/pagecount);
        if(index==0){
            pageInfo.currentpage = 1;
            pageInfo.pageLeft = 0;
            if(pageInfo.totlepage>1){
                pageInfo.pageRight = 1;
            }else{
                pageInfo.pageRight = 0;
            }
        }else{
            var page = index/pagecount;
            if(page >= 1){
                page = parseInt(page.toString().split('.')[0])+1;
            }else{
                page = 1;
            }
            pageInfo.currentpage = page;
            if(pageInfo.currentpage>1){
                pageInfo.pageLeft = 1;
            }else{
                pageInfo.pageLeft = 0;
            }
            if(pageInfo.totlepage-pageInfo.currentpage>0){
                pageInfo.pageRight = 1;
            }else{
                pageInfo.pageRight = 0;
            }
        }
        return pageInfo;
    };
    /**
     * 获取分页信息
     * @param currentpage 开始页
     * @param totlepage 总页数
     * @return pageInfo 分页信息
     */
    owner.getPageInfoTwo = function (currentpage,totlepage) {
        var pageInfo = {
            currentpage:currentpage,//当前页
            pageLeft: 0,//0是不可点击，1反之
            pageRight: 0,//0是不可点击，1反之
            totlepage: totlepage,//总页数
        };
        if(currentpage==1){
            pageInfo.currentpage = 1;
            pageInfo.pageLeft = 0;
            if(pageInfo.totlepage>1){
                pageInfo.pageRight = 1;
            }else{
                pageInfo.pageRight = 0;
            }
        }else{
            if(pageInfo.currentpage>1){
                pageInfo.pageLeft = 1;
            }else{
                pageInfo.pageLeft = 0;
            }
            if(pageInfo.totlepage-pageInfo.currentpage>0){
                pageInfo.pageRight = 1;
            }else{
                pageInfo.pageRight = 0;
            }
        }
        return pageInfo;
    };
    /**
     * 获取当前时间
     * @param format :yyyy-MM-dd HH:MM:SS yyyy-MM-dd MM-dd HH:MM:SS HH:MM MM:SS
     * @return newDate(yyyy-MM-dd HH:MM:SS)
     */
    owner.getNowFormatDate = function (format = 'yyyy-MM-dd HH:MM:SS',time = new Date()) {
        let date = new Date(time);
        let seperator1 = "-";
        let seperator2 = ":";
        let month = date.getMonth() + 1;
        let strDate = date.getDate();
        let getHours = date.getHours();
        let getMinutes = date.getMinutes();
        let getSeconds = date.getSeconds();

        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        if (getHours >= 0 && getHours <= 9) {
            getHours = "0" + getHours;
        }
        if (getMinutes >= 0 && getMinutes <= 9) {
            getMinutes = "0" + getMinutes;
        }
        if (getSeconds >= 0 && getSeconds <= 9) {
            getSeconds = "0" + getSeconds;
        }

        let currentdate = '';
        switch (format){
            case 'MM-dd':
                currentdate = month + seperator1 + strDate;
                break;
            case 'yyyy-MM':
                currentdate = date.getFullYear() + seperator1 + month;
                break;
            case 'yyyy-MM-dd':
                currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
                break;
            case 'HH:MM':
                currentdate = getHours + seperator2 + getMinutes;
                break;
            case 'HH:MM:SS':
                currentdate = getHours + seperator2 + getMinutes + seperator2 + getSeconds;
                break;
            case 'MM:SS':
                currentdate = getMinutes + seperator2 + getSeconds;
                break;
            default :
                currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + getHours + seperator2 + getMinutes + seperator2 + getSeconds;
                break;
        }
        return currentdate;
    };
    /**
     * 获取图片信息
     * @param element
     * @param callback
     * @callback imgInfo
     */
    owner.getImgInfo = function (element,callback){
        var imgInfo = {
            width: 0,
            height: 0,
            size: 0,
            src: ''
        };
        var input = document.getElementById(element);
        if(input.files){
            //读取图片数据
            var f = input.files[0];
            var reader = new FileReader();
            reader.onload = function (e) {
                var data = e.target.result;
                //加载图片获取图片真实宽度和高度
                var image = new Image();
                imgInfo.src = data;
                image.src= data;
                image.onload=function(){
                    imgInfo.width = image.width;
                    imgInfo.height = image.height;
                    imgInfo.size = f.size;
                    callback(imgInfo);
                };
            };
            reader.readAsDataURL(f);
        }else{
            var image = new Image();
            imgInfo.src = input.value;
            image.src = input.value;
            image.onload =function(){
                imgInfo.width = image.width;
                imgInfo.height = image.height;
                imgInfo.size = image.fileSize;
                callback(imgInfo);
            };
        }
    }
}($,window.suixun = {}));
/**
 * 进入页面为页面添加模糊层
 * 数据加载完成后隐藏模糊层
 */
window.onload = function () {
    var imgUrl = "../img/icon/loding.gif";
    $(document.body).append("<div class='pageLoding' id='pageLoding'> <div class='model_layout_loding'></div> <div class='lodingMain'><img src='"+imgUrl+"' alt=''> </div> </div>");
};
/**
 * 验证传入后台json格式
 */
function getJsonDataNotEmpty(param,name,value){
    if(value==null || value.trim()==""){
        return param;
    }else{
        if(param.indexOf(":")>-1){
            return param+',"'+name+'":'+value;
        }else{
            return param+'"'+name+'":'+value;
        }
    }
}
/**
 * 验证传入后台json格式
 */
function getJsonDataNotNull(param,name,value){
    if(value==null){
        return param;
    }else{
        if(param.indexOf(":")>-1){
            return param+',"'+name+'":'+value;
        }else{
            return param+'"'+name+'":'+value;
        }
    }
}
$(document).keyup(function(e) {
    var eCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    var eleObj = document.getElementById("popupFrame");
    if (eCode == 27 && eleObj){
        $(".popupFrame").remove();
    }
});
/**
 * 设置分页是否显示
 */
function showPage(){
    if($(".page-list").is(":hidden")){
        $(".page-list").show();
    }else{
        $(".page-list").hide();
    }

}
/**
 * 设置一页显示条数
 * @param num
 */
function setPage(num){
    localStorage.pagecount = num;
    pagecount = num;
    showPage();
    $(".page-number-list").text(pagecount);//做商户中心-商户管理的时候添加
}
/**
 * 转时间格式
 * format('yyyy-MM-dd h:m:s')
 * new Date(parseInt(value.optime)).format('yyyy-MM-dd h:m:s')
 * @param format
 * @returns {*}
 */
Date.prototype.format = function(format) {
    var date = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S+": this.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1
                ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
    }
    return format;
};